(function (vc, vm) {

    vc.extends({
        data: {
            auditAffiliateUserInfo: {
                auId: '',
                level:'',
                userName:'',
                state: '',
                auditReason: '',
                remark:'',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('auditAffiliateUser', 'openAuditAffiliateUserModal', function (_params) {
                vc.component.refreshauditAffiliateUserInfo();
                $('#auditAffiliateUserModel').modal('show');
                vc.copyObject(_params, vc.component.auditAffiliateUserInfo);
                $that.auditAffiliateUserInfo.state = '';
                vc.component.auditAffiliateUserInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods: {
            auditAffiliateUserValidate: function () {
                return vc.validate.validate({
                    auditAffiliateUserInfo: vc.component.auditAffiliateUserInfo
                }, {
                    'auditAffiliateUserInfo.state': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "审核状态不能为空"
                        },
                    ],
                    'auditAffiliateUserInfo.auditReason': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "原因不能为空"
                        }]

                });
            },
            auditAffiliateUser: function () {
                if (!vc.component.auditAffiliateUserValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    'affiliateUser.auditAffiliateUser',
                    JSON.stringify(vc.component.auditAffiliateUserInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#auditAffiliateUserModel').modal('hide');
                            vc.emit('affiliateUserManage', 'listAffiliateUser', {});
                            return;
                        }
                        vc.message(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);
                    });
            },
            refreshauditAffiliateUserInfo: function () {
                vc.component.auditAffiliateUserInfo = {
                    auId: '',
                    level:'',
                    userName:'',
                    state: '',
                    auditReason: '',
                    remark:'',
                }
            },
            _level: function (_state) {
                if(_state == "1"){
                    return "一级"
                }
                if(_state == "2"){
                    return "二级"
                }
            },
            _auditState: function (_state) {
                if(_state == "0"){
                    return "待审核"
                }
                if(_state == "1"){
                    return "审核通过"
                }
                if(_state == "2"){
                    return "已拒绝"
                }
            },
        }
    });

})(window.vc, window.vc.component);
